package com.edu.exam.entity.quality.workflow;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 审核记录实体类
 * [所属模块] E-05 巡考管理模块
 * 对应数据库表：audit_record
 *
 * 根据E-05巡考管理模块设计文档实现
 * 管理审核过程的操作记录，提供完整的审计追踪。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "audit_record")
@Comment("审核记录表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditRecord {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 审核记录唯一标识符
     */
    @NotBlank(message = "审核记录ID不能为空")
    @Size(max = 50, message = "审核记录ID长度不能超过50个字符")
    @Column(name = "record_id", nullable = false, length = 50, unique = true)
    private String recordId;

    /**
     * 关联的审核流程实例ID
     */
    @Size(max = 50, message = "审核流程实例ID长度不能超过50个字符")
    @Column(name = "instance_id", length = 50)
    private String instanceId;

    /**
     * 关联的审核任务ID
     */
    @Size(max = 50, message = "审核任务ID长度不能超过50个字符")
    @Column(name = "task_id", length = 50)
    private String taskId;

    /**
     * 操作类型（CREATE-创建，UPDATE-更新，DELETE-删除，ASSIGN-分配，START-开始，COMPLETE-完成，CANCEL-取消）
     */
    @NotBlank(message = "操作类型不能为空")
    @Size(max = 20, message = "操作类型长度不能超过20个字符")
    @Column(name = "operation_type", nullable = false, length = 20)
    private String operationType;

    /**
     * 操作描述
     */
    @Size(max = 500, message = "操作描述长度不能超过500个字符")
    @Column(name = "operation_description", length = 500)
    private String operationDescription;

    /**
     * 操作结果（SUCCESS-成功，FAILED-失败，PARTIAL-部分成功）
     */
    @Size(max = 20, message = "操作结果长度不能超过20个字符")
    @Column(name = "operation_result", length = 20)
    private String operationResult;

    /**
     * 操作人员ID
     */
    @Size(max = 50, message = "操作人员ID长度不能超过50个字符")
    @Column(name = "operator_id", length = 50)
    private String operatorId;

    /**
     * 操作人员姓名
     */
    @Size(max = 100, message = "操作人员姓名长度不能超过100个字符")
    @Column(name = "operator_name", length = 100)
    private String operatorName;

    /**
     * 操作时间
     */
    @NotNull(message = "操作时间不能为空")
    @Column(name = "operation_time", nullable = false)
    private LocalDateTime operationTime;

    /**
     * 操作前状态（JSON格式）
     */
    @Column(name = "before_state", columnDefinition = "TEXT")
    private String beforeState;

    /**
     * 操作后状态（JSON格式）
     */
    @Column(name = "after_state", columnDefinition = "TEXT")
    private String afterState;

    /**
     * 操作IP地址
     */
    @Size(max = 50, message = "操作IP地址长度不能超过50个字符")
    @Column(name = "ip_address", length = 50)
    private String ipAddress;

    /**
     * 用户代理信息
     */
    @Size(max = 500, message = "用户代理信息长度不能超过500个字符")
    @Column(name = "user_agent", length = 500)
    private String userAgent;

    /**
     * 操作参数（JSON格式）
     */
    @Column(name = "operation_parameters", columnDefinition = "TEXT")
    private String operationParameters;

    /**
     * 异常信息
     */
    @Column(name = "exception_info", columnDefinition = "TEXT")
    private String exceptionInfo;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

}